package com.jinmdz.app.api.api.service;

import com.jinmdz.app.api.base.BaseService;
import com.jinmdz.app.api.wrapper.DictionaryWrapper;
import com.jinmdz.app.dao.dao.TakeAshDao;
import com.jinmdz.app.dao.model.cremation.SearchTakeAshData;
import com.jinmdz.app.dao.model.cremation.SearchTakeAshViewItem;
import com.jinmdz.fmis.common.ext.StringBuilderExt;
import com.jinmdz.fmis.common.util.BeanUtil;
import com.jinmdz.fmis.common.util.DataUtil;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.mapper.mapper.CremationMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

@Service("takeAshService")
public class TakeAshService extends BaseService {
    @Resource
    private TakeAshDao takeAshDao;
    @Resource
    private DictionaryWrapper dictionaryWrapper;

    /**
     *骨灰发放待取灰信息查询列表加载接口
     * @author shan
     * @date 2020/8/25 14:21
     * @param data
     * @return com.jinmdz.fmis.core.base.BaseResult<java.util.ArrayList<com.jinmdz.app.dao.model.cremation.SearchTakeAshViewItem>>
     */
    public BaseResult<ArrayList<SearchTakeAshViewItem>> loadTakeAshList(SearchTakeAshData data) {
        //骨灰发放待取灰信息查询
        ArrayList<SearchTakeAshViewItem> loadItems = takeAshDao.listTakeAshs(data);
        // 设置数据字典文本
        dictionaryWrapper.resetDataText(loadItems);
        // 处理查询数据
        loadItems.forEach(loadItem -> {
            if (DataUtil.valid(loadItem.getAgentUnit())) {
                StringBuilderExt builder = new StringBuilderExt();
                builder.format("{0} {1}", loadItem.getAgentUnit(), loadItem.getAgentName());
                loadItem.setAgentName(builder.toString());
            }

        });
        ArrayList<SearchTakeAshViewItem> loadData = BeanUtil.copy2List(loadItems, SearchTakeAshViewItem.class);
        // 火化档案（逝者）信息查询
        //  ArrayList<SearchTakeAshViewItem> loadItems = loadCremationArchivesViewItems(data);
        // 初始化返回实体
        // ArrayList<SearchTakeAshViewItem> loadData = getSearchLoadData(loadItems);
        return successList(loadData);
    }
}
